-- ======================================================

CREATE OR REPLACE FUNCTION ZOEDEVOPS.ZOEFUN_CRYPTO_KEY(iv_db_id IN VARCHAR2 DEFAULT NULL)
	RETURN VARCHAR2
	
-- Created in 2019.06.18 by polarbears
-- Copyright (c) 20xx, CHINA and/or affiliates.
-- All rights reserved.
--	Name:
-- 		zoefun_crypto_key.pls
--	Description:
-- 		基础安全包
--  Relation:
--      
--	Notes:
--		基本注意事项
--	修改 - （年-月-日） - 描述
--

AS
    -- 错误信息参数
    ln_return       NUMBER;
    lv_secret_key   VARCHAR2(256);
    lv_key_id   VARCHAR2(128);
BEGIN
    ZOEDEVOPS.ZOEPRC_SET_DEVOPS_CONTEXT('ERROR_PROGRAM','ZOEDEVOPS.ZOEFUN_CRYPTO_KEY');
    IF iv_db_id IS NULL THEN
        lv_key_id := SYS_CONTEXT('ZOE_DEVOPS_CONTEXT', 'DB_ID');
    ELSE
        lv_key_id := iv_db_id;
    END IF;
	SELECT KEY_VALUE INTO lv_secret_key FROM ZOEDEVOPS.DVP_PROJECT_SECRET_KEY WHERE KEY_ID#=lv_key_id;
    RETURN lv_secret_key;
  EXCEPTION 
    WHEN OTHERS THEN
        ln_return := ZOEDEVOPS.ZOEFUN_WERROR_LOG(
            ZOEDEVOPS.ZOEFUN_WERROR_JSON(
                SYS_CONTEXT('ZOE_DEVOPS_CONTEXT','ERROR_PROGRAM')||
                ','||SQLERRM||','||
                TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS'))
            );
        RETURN '-1';
END;
/


